package org.example.group5back.service;

import org.example.group5back.entity.EquipmentEntity;
import org.example.group5back.mapper.EquipmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EquipmentService {
    @Autowired
    EquipmentMapper equipmentMapper;
    public List<EquipmentEntity> finAllEquipment(){
        return equipmentMapper.findAllEquipment();
    }
    public boolean saveEquipment(EquipmentEntity equip){
        System.out.println(equip.getEq_id());
        List<EquipmentEntity> equipmentEntityList = equipmentMapper.findAllEquipment();
        Integer next_eq_id = equipmentEntityList.size() + 1;
        System.out.println(next_eq_id);
        if(equip.getEq_id() > 0){
            return equipmentMapper.updateEquipment(equip);
        }else{
            equip.setEq_id(next_eq_id);
            return equipmentMapper.insertEquipment(equip);
        }
    }
    public boolean deleteEquipment(Integer eq_id){
        boolean result = equipmentMapper.deleteEquipment(eq_id);
        equipmentMapper.updateAfterDelete(eq_id);
        return result;
    }
    public List<EquipmentEntity> showPageLimit(Integer pageNum,Integer pageSize){
        return equipmentMapper.showPageLimit(pageNum,pageSize);
    }
    public List<EquipmentEntity>  selectByName(String eq_name,String eq_data,String eq_after_sale,String eq_type){
        if(eq_name == null){
            System.out.println("1");
        }
        return equipmentMapper.selectByName(eq_name,eq_data,eq_after_sale,eq_type);
    }
}
